package com.wk.slaveNodes;

import java.util.concurrent.SynchronousQueue;

import com.wk.constains.net.SendUtils;
import com.wk.job.Job;
import com.wk.job.heartbeat.slave.JobStateHeartbeatSource;

public class Calculate implements Runnable{
	
	private SynchronousQueue<Job> calculatingAJob = null;
	private JobStateHeartbeatSource heartbeatSource =null;
	public boolean isWorking = true;
	
	public Calculate(SynchronousQueue<Job> calculatingAJob,JobStateHeartbeatSource heartbeatSource) {
		this.calculatingAJob = calculatingAJob;
		this.heartbeatSource = heartbeatSource;
	}
	@Override
	public void run() {
		while(isWorking){
			try {
				System.out.println("等待获取一个Job。。。");
				heartbeatSource.observe(null);
				Job job = calculatingAJob.take();
				heartbeatSource.observe(job);
				CalculateAJob.Calculate.calculate(job);
			//	SendUtils.sendMessage("localhost", 8086, job);
				heartbeatSource.sendImmediately();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

}
